<?php

namespace App\Http\Requests\Admin\Customer\Store;

use App\Http\Requests\ApiRequest;
use App\Models\Store\Store;
use App\Services\Locale\Language;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\UploadedFile;
use Illuminate\Validation\Rule;

/**
 * @property string name
 * @property int type
 * @property string phone
 * @property string address
 * @property UploadedFile store_img
 * @property string remark
 * @property int is_deleted
 * @property string province
 * @property string city
 * @property string district
 * @property string email
 * @property string has_youzan
 * @property string youzan_authorizer_id
 */
class StoreUpdateRequest extends ApiRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $data = [
            'name'       => ['required', 'string', 'max:'.self::MAX_STRING],
            'type'       => ['required', 'int', Rule::in([1, 2])],
            'address'    => 'required|string|max:'.self::MAX_STRING,
//            'province'   => 'required|string',
//            'city'       => 'required|string',
//            'district'   => 'required|string',
            'remark'     => 'nullable|string|max:'.self::MAX_STRING,
            'email'      => 'nullable|email',
            'store_img'  => 'nullable',
            'is_deleted' => ['nullable', 'int', Rule::in([0, 1])],
            'phone'      => ['required', 'string', 'max:'.self::MAX_STRING],

            'has_youzan'  => 'nullable|int|in:0,1',
        ];

//        if (app()->getLocale() === Language::ZH_CN) {
//            $data['phone'] = ['required', 'regex:/^1[34578][0-9]{9}$|^((0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/'];
//        } else {
//            $data['phone'] = ['required', 'string'];
//        }

        return $data;
    }

    /**
     * @return array
     */
//    public function messages()
//    {
//        return [
//            'name.*'       => '店铺名称必须是唯一的',
//            'type.*'       => '店铺类型必须是数字1或2',
//            'address.*'    => '店铺的地址必须是字符串',
//            'remark.*'     => '店铺备注信息',
//            'email.*'      => '店铺的邮箱必须是合法的邮箱',
//            'store_img.*'  => '店铺的头像必须是上传的图片',
//            'phone.*'      => '店铺手机号必须是合法的',
//            'is_deleted.*' => '店铺状态是0或者1',
//        ];
//    }
}
